<template>
  <div class="search">
    <!-- 搜索模块 -->
    <el-form ref="formRef" :model="formSearch" label-width="80px" size="large">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="用户名" prop="name">
            <el-input v-model="formSearch.name" placeholder="请输入用户名" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" prop="realname">
            <el-input v-model="formSearch.realname" placeholder="请输入姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="手机号码" prop="cellphone">
            <el-input v-model="formSearch.cellphone" placeholder="请输入手机号码" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="enable">
            <el-select placeholder="Activity zone" style="width: 100%" v-model="formSearch.enable">
              <el-option label="启用" :value="1" />
              <el-option label="禁用" :value="0" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <el-date-picker
              v-model="formSearch.createAt"
              type="daterange"
              range-separator="To"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 重置和查询 -->
    <div class="btns">
      <el-button size="large" @click="resetClickInfo">重置</el-button>
      <el-button size="large" @click="clickQueryInfo" type="primary">查询</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ElForm } from 'element-plus'
import { reactive, ref } from 'vue'
const formSearch = reactive({
  realname: '',
  name: '',
  cellphone: '',
  enable: 1,
  createAt: ''
})
const emit = defineEmits(['userQueryList', 'resetQueryList'])
const formRef = ref<InstanceType<typeof ElForm>>()
// 重置该表单项，将其值重置为初始值，并移除校验结果
// 利用表单的 resetFields方法 重置信息
function resetClickInfo() {
  formRef.value?.resetFields()
  emit('resetQueryList')
}
// 查询用户列表
function clickQueryInfo() {
  emit('userQueryList', formSearch)
}
</script>

<style lang="less" scoped>
.search {
  background-color: var(--el--page--search--bg--);
  border-radius: 10px;
  padding: 20px 20px 20px 0;
}
.btns {
  text-align: right;
}
</style>
